import request from '@/utils/request'

// 查询代码生产记录列表
export function listRecords(query) {
  return request({
    url: '/generator/records/list',
    method: 'get',
    params: query
  })
}

// 查询代码生产记录详细
export function getRecords(id) {
  return request({
    url: '/generator/records/' + id,
    method: 'get'
  })
}

// 新增代码生产记录
export function addRecords(data) {
  return request({
    url: '/generator/records',
    method: 'post',
    data: data
  })
}

//保存草稿
export function saveDraft(data) {
  return request({
    url: '/generator/records/saveDraft',
    method: 'post',
    data: data
  })
}

// 修改代码生产记录
export function updateRecords(data) {
  return request({
    url: '/generator/records',
    method: 'put',
    data: data
  })
}

// 删除代码生产记录
export function delRecords(id) {
  return request({
    url: '/generator/records/' + id,
    method: 'delete'
  })
}

//提交审核
export function toExamine(id) {
  return request({
    url: '/generator/records/toExamine/' + id,
    method: 'get'
  })
}

//审核通过
export function examineSuccess(id) {
  return request({
    url: '/generator/records/examineSuccess/' + id,
    method: 'get'
  })
}

//驳回
export function toReject(id, message) {
  let data = {
    "message": message
  }
  return request({
    url: '/generator/records/toReject/' + id,
    method: 'get',
    params: data
  })
}

//todo 生成代码
export function postGenCode(tables, id, model) {
  // 构造一个 JSON 对象，属性名必须与后端参数名一致
  let data = {
    "tables": tables,
    "id": id,
    "model": model
  };

  return request({
    url: '/generator/records/code',
    method: 'post',
    data: data, // 注意这里发送的是一个对象
  });
}

//查看详情
export function getCheck(id) {
  return request({
    url: '/generator/records/check/' + id,
    method: 'get'
  })
}
